﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using AbstractFramework.LogicControl;
using AbstractFramework.Constant;
using AbstractFramework.Display;
namespace ControlLib
{
    /// <summary>
    /// Interaction logic for FireButtonDisplay.xaml
    /// </summary>
    public partial class FireButtonDisplay : UserControl
    {
        private IButtonFactory buttonFactory;
        private IElevator[] logicElevators;
        private bool isFiring = false;
        public FireButtonDisplay()
        {
            InitializeComponent();
        }

        void waringBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!isFiring)
            {
                IFireButton button = (IFireButton)buttonFactory.createButton(ButtonType.fireButton);
                button.createButtonRequisition();

                //停用所有的电梯内部按钮
                foreach (IElevator ele in logicElevators)
                {
                    ele.InsideButtonPanel.setEnabled(false);
                }
                //停用每一层按钮
                foreach (IOutsideButtonPanelDisplay obp in logicElevators[0].OutsideButtonPanel)
                {
                    obp.setEnabled(false);
                }
                this.waringBtn.Content = "解除报警";
                this.isFiring = true;
            }
            else
            {
                //启用所有的电梯内部按钮
                foreach (IElevator ele in logicElevators)
                {
                    ele.InsideButtonPanel.setEnabled(true);
                }
                //启用每一层按钮
                foreach (IOutsideButtonPanelDisplay obp in logicElevators[0].OutsideButtonPanel)
                {
                    obp.setEnabled(true);
                }
                this.waringBtn.Content = "按下报警";
                this.isFiring = false;
            }
        }

        public void initialize(IButtonFactory buttonFactory, IElevator[] logicElevators)
        {
            this.buttonFactory = buttonFactory;
            this.logicElevators = logicElevators;
            this.waringBtn.Click += new RoutedEventHandler(waringBtn_Click);
        }
    }
}
